package pATT.profilingAlgorithm.PersonalSearcher;
import java.util.Iterator;



/**
 * Drops any words of length maximumSize or below (default is three).
 *
 * @author <a href="mailto:trbauer@indiana.edu">Travis Bauer</a>
 */
public class DropNumbers implements DocumentFilter {

  public DropNumbers() {}

  public Instance applyFilter(Instance i) {
    TermVector v = i.getVector();
    TermVector newv = new TermVector();
    
    for (Iterator it=v.termIterator(); it.hasNext(); ) {
      String s = it.next().toString();
      if ((!isValidNumber(s))&&(!isParcialNumber(s))) {
      	newv.put(s,v.get(s));
      }
    }
		i.setVector(newv);
		return i;
  }

	public static boolean isValidNumber(String number){
		number = number.trim();
  	if (number.length()==0)
			return false;
		for(int i=0; i<number.length(); i++){
			if(!(Character.isDigit(number.charAt(i))))
				return false;
		}
		return true;
	}

	public static boolean isParcialNumber(String number){
		number = number.trim();
  	if (number.length()==0)
			return false;
		for(int i=0; i<number.length(); i++){
			if(Character.isDigit(number.charAt(i)))
				return true;
		}
		return false;
	}

}